import javax.swing.*;
import javax.swing.tree.TreeNode;
import java.util.Scanner;

public class Main {
    //二叉树遍历
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String str = in.nextLine();
            TreeNode root = createTree(str);
            //中序遍历
            inorder(root);
        }
    }
     public static int i = 0;
    private static TreeNode createTree( TreeNode str){
        TreeNode root = null;
        char ch = str.charAt(i);
        if(ch != '#'){
            root = new TreeNode(ch) {
                i++;
                root.left = createTree(str);
                root.right = createTree(str);
            }else{
                i++;
            }
            return; root;
        }

    private static void inorder(TreeNode root){
            if(root == null){
                return;
            }
            inorder(root.left);
            System.out.print(root.val+' ');
        }
        inorder(root.right);
        public static void test(TreeNode root){

        }
    }














}
//对称二叉树
class Solution {
    public boolean isSymmetric(TreeNode root) {
         if(root == null){
             return true;
         }
       return  isSymmetricChild(root.left,root.right) ;
    }
    public  boolean isSymmetricChild(TreeNode leftTree, TreeNode rightTree ){
        //1.结构上的判断
        if(leftTree == null && rightTree != null
                || leftTree != null && rightTree == null){
            return  false;
        }
        if(leftTree == null && rightTree == null){
            return true;
        }
        //2. 值
        if(leftTree.val != rightTree.val){
            return  false;
        }
        //3. 都不为空 且当前节点值一样了，继续判断左和右
        return  isSymmetricChild(leftTree.left,rightTree.right &&
                isSymmetricChild ( leftTree.right,rightTree.left);

    }

    //平衡二叉树
    public boolean isBalanced(TreeNode root) {
        if (root == null) {
            return true;
        }
        return getHeight(root) >= 0;
    }
   public int getHeight(TreeNode root){
        if(root == null){
            return  0;
        }
        int leftHeight = getHeight(root.left);
        if(leftHeight < 0){
            return -1;
        }
        int rightHeight = getHeight(root.right);
        if(leftHeight >= 0 && rightHeight >= 0 &&
                Math.abs (leftHeight - rightHeight) <= 1){
            return Math.max(leftHeight,rightHeight)+1;
        }else{
            return  -1;
        }
   }


};